import api from '../../api/api'
Page({

  /**
   * 页面的初始数据
   */
  data: {
		active: '',
		personOrderlist: [],
		page: 1,
		row: 10,
    total: 0,
    phone:'',
    searchCondition:'',
  },
  onChange(e) {
		let that = this
		that.setData({
			active: e.detail.name,
			page: 1,
			// listItems: []
    })
    that.getPhone()
		// that.getList()
	},
	
	// async getList() {
	// 	try {
	// 		let that = this
	// 		let params = {
	// 			shippingStatus: that.data.active,
	// 			page: that.data.page,
	// 			row: that.data.row
	// 		}
	// 		console.log('请求参数', params)
	// 		// 请求接口
	// 		// const data = await getpersonalorder(params)
	// 		that.setData({
	// 			listItems: that.data.listItems.concat(data.list),
	// 			total: data.total
	// 		})
	// 	} catch (error) {
	// 		console.log(error)
	// 	}
	// },
	
  goToMyBack(){
    wx.navigateBack()
  },
  goToUserEvaluation(data){
    let shippingOrderNumber = data.currentTarget.dataset.index
    wx.navigateTo({
      url:'/pages/userEvaluation/userEvaluation?shippingOrderNumber='+shippingOrderNumber
    })
  },
 goToOrderDetail(data){
  let shippingOrderNumber = data.currentTarget.dataset.index
    wx.navigateTo({
      url:'/pages/orderDetail/orderDetail?shippingOrderNumber='+shippingOrderNumber
    })
  },
  onSearch(e){
  let that = this
  that.data.searchCondition =e.detail
  // console.log(that.data.searchCondition,'11111');
  },
  onClick(){
    let that = this;
    that.getPhone()
  },
  clearSearch(){
    let that = this;
    that.getPhone()
  },
  getPhone(){
    let that =this
    let id = wx.getStorageSync('id')
    api.post('/userInfoApp/getById', {id:id}).then(res => {
      that.getpersonalorder(res.data.phone)
   })
  },
  getpersonalorder(e) {
    // 改变this指向  
    let that = this;
    let id = wx.getStorageSync('id') 
    that.setData({
      id:id,
    })
		let userInfoReq = {
				shippingStatus: that.data.active,
				page: that.data.page,
        row: that.data.row,
        searchCondition:that.data.searchCondition,
        id:that.data.id,
        phone:e
      }
      // console.log('请求参数', userInfoReq)
      if(userInfoReq.shippingStatus == 'all'){
        userInfoReq.shippingStatus = ''
      }
    api.post('/userInfoApp/findUserPage', userInfoReq).then(res => {
       that.setData({
        personOrderlist :res.data,
        total:res.data.total
       })
    })
    .catch(err => {
    wx.showToast({
      icon:'none',
      title: err.message,
      duration: 2000
    })
   })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {//此处接收传递过来的参数wx.navigateTo跳转时传递的参数
		let that = this
    //如果要在页面中使用
    that.setData({
      active: options.active
    })
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let that = this
    that.getPhone()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
		let that = this
		// console.log('触底')
    if (that.data.page * 10 < that.data.total) {
      that.setData({
        page: that.data.page += 1
      })
      that.getpersonalorder()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})